home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2005 October / PCWOCT05.iso / Software / FromTheMag / Ant Movie Catalog 3.5.0.2 / amc_install.exe / {app} / Scripts / caratulasdecine + Google (ES).ifs < prev    next >
Text File  |  2005-03-13  |  5KB  |  161 lines

  1. (***************************************************
  2.  
  3. Ant Movie Catalog importation script
  4. www.antp.be/software/moviecatalog/
  5.  
  6. [Infos]
  7. Authors=japg2000 (japg2000@terra.es) and micmic (micmic@dieznet.com)
  8. Title=CaratulasDeCine+Google
  9. Description=Large Picture importation script for caratulasdecine
  10. Site=www.caratulasdecine.com
  11. Language=ES
  12. Version=1.0
  13. Requires=3.5.0
  14. Comments=
  15. License=The source code of the script can be used in another program only if full credits to script author and a link to Ant Movie Catalog website are given in the About box or in the documentation of the program.|
  16. GetInfo=1
  17.  
  18. [Options]
  19.  
  20. ***************************************************)
  21.  
  22. program Caratulasdecine;
  23. var
  24.   MovieName: string;
  25. const
  26.   Dominio = 'www.caratulasdecine.com';
  27.   BaseURL1 = 'http://www.google.com/custom?hl=es&ie=ISO-8859-1&cof=&domains=';
  28.   BaseURL2 = '&q=';
  29.   BaseURL3 = '&btnG=B%FAsqueda+en+Google&sitesearch=';
  30.  
  31. function FindLine(Pattern: string; List: TStringList; StartAt: Integer): Integer;
  32. var
  33.   i: Integer;
  34. begin
  35.   result := -1;
  36.   if StartAt < 0 then
  37.     StartAt := 0;
  38.   for i := StartAt to List.Count-1 do
  39.     if Pos(Pattern, List.GetString(i)) <> 0 then
  40.     begin
  41.       result := i;
  42.       Break;
  43.     end;
  44. end;
  45.  
  46. function EliminaInicio(S: string; CR: string): string;
  47. begin
  48.   result := S;
  49.   while Pos(CR, result) = 1 do
  50.   begin
  51.     Delete(result, 1, Length(CR));
  52.   end;
  53. end;
  54.  
  55. function CadenaEntre(var S: string; StartTag: string; EndTag: string): string;
  56. var
  57.   InicioPos: Integer;
  58. begin
  59.   InicioPos := Pos(StartTag, S);
  60.   Delete(S, 1, InicioPos + Length(StartTag) - 1);
  61.   InicioPos := Pos(EndTag, S);
  62.   result := copy(S, 1, InicioPos - 1);
  63.   Delete(S, 1, InicioPos + 1);
  64. end;
  65.  
  66. procedure AnalyzePage(Address: string);
  67. var
  68.   Page: TStringList;
  69.   LineNr: Integer;
  70.   PosIni, PosFin: Integer;
  71.   Line, SubLine: string;
  72.   Title, DirURL: string;
  73.   txtTemp: string;
  74. begin
  75.   Page := TStringList.Create;
  76.   Page.Text := GetPage(Address);
  77.   if Pos('No se encontr≤ ninguna pßgina', Page.Text) > 0 then
  78.   begin
  79.     ShowMessage('No se ha encontrado ning·n artφculo por tφtulo.');
  80.   end else
  81.   begin
  82.     PickTreeClear;
  83.     PickTreeAdd('Resultados de la b·squeda para "' + MovieName + '" (' + Dominio + ') por Google:', '');
  84.    
  85.     Page.Text := StringReplace(Page.Text, '<br>', #13#10);
  86.     Page.Text := StringReplace(Page.Text, '<p class=g>', #13#10 + '<p class=g>');
  87.  
  88.     // buscamos los resultados
  89.     LineNr := 0;
  90.  
  91.     while LineNr < Page.Count do
  92.     begin
  93.       SubLine := Page.GetString(LineNr);
  94.       txtTemp := '<p class=g><a href=';
  95.       PosIni := pos(txtTemp, SubLine);
  96.       if PosIni > 0 then
  97.       begin
  98.         SubLine := Copy(SubLine, PosIni + Length(txtTemp), Length(SubLine));
  99.         txtTemp := '>';
  100.         PosFin := pos(txtTemp, SubLine);
  101.         DirURL := Copy(SubLine, 1, PosFin - 1);
  102.         DirURL := StringReplace(DirURL, '"', '');
  103.        
  104.         SubLine := Copy(SubLine, PosFin + Length(txtTemp), Length(SubLine));
  105.         txtTemp := '</a>';
  106.         PosFin := pos(txtTemp, SubLine);
  107.         Title := Copy(SubLine, 1, PosFin - 1);
  108.         HTMLRemoveTags(Title);
  109.  
  110.         //ShowMessage(Title + '-->' + DirURL);
  111.         if ((Title <> 'Actualidad') and (Title <> 'Mercadillo de cine')) then
  112.           PickTreeAdd(Title, DirURL); 
  113.       end;
  114.       LineNr := LineNr + 1;
  115.     end;
  116.  
  117.     Page.Free;
  118.     if PickTreeExec(Address) then
  119.       AnalyzeMoviePage(Address);
  120.   end;
  121. end;
  122.  
  123. procedure AnalyzeMoviePage(Address: string);
  124. var
  125.   MoviePage: TStringList;
  126.   LineNr: Integer;
  127.   Line: string;
  128. begin
  129.  
  130.   MoviePage := TStringList.Create;
  131.   MoviePage.Text := GetPage(Address);
  132.  
  133.   LineNr := FindLine('<title>', MoviePage, 0);
  134.   Line := MoviePage.GetString(LineNr);
  135.   Line := CadenaEntre(Line, '<title>', '</title>');
  136.   SetField(fieldTranslatedTitle, Line);
  137.  
  138.   LineNr := FindLine('<p align="center"><img src="', MoviePage, 0);
  139.   Line := MoviePage.GetString(LineNr);
  140.   Line := CadenaEntre(Line, '<p align="center"><img src="', '" ');
  141.   Line := EliminaInicio(Line, '../');
  142.   GetPicture('http://www.caratulasdecine.com/' + Line);
  143.  
  144.   MoviePage.Free;
  145.   //DisplayResults;
  146. end;
  147.  
  148. // bmicmic: Bucle Principal
  149. begin
  150.   if CheckVersion(3,5,0) then
  151.   begin
  152.     MovieName := GetField(fieldOriginalTitle);
  153.     if MovieName = '' then MovieName := GetField(fieldTranslatedTitle);
  154.  
  155.     Input('Importar de ' + Dominio + ' (por Google)', 'Introduce el Titulo de la Pelicula:', MovieName);
  156.     AnalyzePage(BaseURL1 + Dominio + BaseURL2 + UrlEncode(MovieName) + BaseURL3 + Dominio);
  157.  
  158.   end else
  159.        ShowMessage('Este script necesita una versi≤n superior de Ant Movie Catalog (al menos la version 3.5.0)');
  160. end.
  161.